import { _decorator, Component, Label, Node, Sprite, SpriteFrame } from 'cc';

import { HttpCom } from '../net/HttpCom';
import { rewardConfig } from '../Adventure/GamePanel';
const { ccclass, property } = _decorator;

@ccclass('RewardItem')
export class RewardItem extends Component {
    @property(SpriteFrame)
    allrewardSprite: Array<SpriteFrame> = [];
    @property(Sprite)
    sprite: Sprite = null;
    @property(Label)
    numLabel: Label = null;
    init() {
        HttpCom.getUserInfo();
        this.numLabel = this.node.getChildByName("numlabel").getComponent(Label);
    }
    setData(data: any) {
        this.sprite.spriteFrame = this.allrewardSprite[rewardConfig[data.name].icon];
        if(data.name == "DIAMOND_ORE"){
            this.numLabel.string = (data.value).toString()

        }else{
            this.numLabel.string = String(Math.floor(Number(data.value)));
        }
    }

}


